using UnityEngine;
using System.Collections;

public class DestructibleCrate : MonoBehaviour {

    public GameObject dieParticles;

    private float fTexOffset = 0;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void Damaged()
    {
        fTexOffset += 0.25f;
        renderer.material.SetTextureOffset("_MainTex", new Vector2(fTexOffset, 0));
    }

    public void Die()
    {
        if (dieParticles)
        {
            GameObject temp = (GameObject)GameObject.Instantiate(dieParticles, transform.position, transform.rotation);
            if (temp.GetComponent<ParticleSystem>())
            {
                temp.GetComponent<ParticleSystem>().Play();
                Destroy(temp, temp.GetComponent<ParticleSystem>().startLifetime);
            }
        }

        Destroy(gameObject);
    }
}
